<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>23.字符串形式的ref</title>
</head>

<body>
    <!-- 准备好一个容器 -->
    <div id="app"></div>
    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom 用于支持 react 操作 dom -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入 label，用于将 jsx 转化为 js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 引入 prop-types，用于对于组件标签属性进行限制 -->
    <script type="text/javascript" src="../js/prop-types.js"></script>

    <!-- 此处必须写 text/babel -->
    <script type="text/babel">

        // 创建组件
        class Demo extends React.Component {

            // 展示左侧数据
            showData = () => {
                // let input1 = document.getElementById("input1")
                // alert(input1.value)

                // console.log(this)
                // console.log(this.refs.input1)

                let { input1 } = this.refs
                alert(input1.value)
            }

            // 失去焦点展示数据
            showData2 = () => {
                let { input2 } = this.refs
                alert(input2.value)
            }

            render() {
                return (
                    <div>
                        <input ref="input1" type="text" placeholder="请输入文字"></input>
                        <button ref="button" onClick={this.showData}>点击我弹出左侧内容</button>
                        <input ref="input2" onBlur={this.showData2} type="text" placeholder="右侧数据" />
                    </div>
                )
            }
        }
        // 渲染组件
        ReactDOM.render(<Demo />, document.getElementById("app"))
    </script>

</body>

</html>